//
//  JQUserLoginVC.m
//  JQLive
//
//  Created by Bruce on 2020/8/7.
//  Copyright © 2020 mlkq. All rights reserved.
//

#import "JQUserLoginVC.h"
#import "MYSimpleWebVC.h"
#import "JQUserSetPwdVC.h"

@interface JQUserLoginVC ()<UITextFieldDelegate>
@property (nonatomic, strong) UIView *loginTopLeftView;
@property (nonatomic, strong) UIView *loginTopRightView;
@property (nonatomic, strong) UIButton *verificationTopLoginBtn;// top 选择
@property (nonatomic, strong) UIButton *pwdTopLoginBtn;// top 选择

@property (nonatomic, strong) UIButton *verificationBottomLoginBtn;// 底部登录
@property (nonatomic, strong) UIButton *pwdBottomLoginBtn;// 底部登录

@property (nonatomic, strong) UIView *loginTopView;
@property (nonatomic, strong) UIView *verificationLoginView;
@property (nonatomic, strong) UIView *pwdLoginView;

@property (nonatomic, strong) UITextField *verificationPhoneTextField; // 验证码登录手机号
@property (nonatomic, strong) UITextField *verificationVerfiTextField;// 验证码登录 验证码
@property (nonatomic, strong) UIButton *verificationBtn;
@property (nonatomic, strong) CAGradientLayer *verificationGl;

// 账号登录 pwdAccountLb
@property (nonatomic, strong) UITextField *pwdAccountTextField;
@property (nonatomic, strong) UITextField *pwdPwdTextField;
@property (nonatomic, strong) UIButton *pwdIsSecretBtn;
@property (nonatomic, strong) CAGradientLayer *pwdGl;
@property (nonatomic, strong) UIButton *pwdForgetBtn;
@end

@implementation JQUserLoginVC

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    [self addTopView];
    [self addNavBar];
}

- (void)addNavBar{
    MY_WEAK;
    
    // 返回
    UIButton *backBtn = [[UIButton alloc] init];
    [backBtn setImage:[UIImage svgImageNamed:@"nav_back" size:CGSizeMake(15, 15)] forState:UIControlStateNormal];
    [self.view addSubview:backBtn];
    [backBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        MY_STRONG;
        make.left.mas_equalTo(strongSelf.view.mas_left).offset(18);
        make.top.mas_equalTo(strongSelf.view.mas_top).offset(48);
        make.size.mas_equalTo(CGSizeMake(22, 22));
    }];
    [backBtn addTapBlock:^(UIButton * _Nonnull btn) {
        [self.navigationController popViewControllerAnimated:YES];
    }];
    
    UILabel *titleLb = [[UILabel alloc] init];
    [self.view addSubview:titleLb];
    [titleLb mas_makeConstraints:^(MASConstraintMaker *make) {
        MY_STRONG;
        make.left.mas_equalTo(strongSelf.view.mas_left).offset(21);
        make.top.mas_equalTo(backBtn.mas_bottom).offset(31);
        make.size.mas_equalTo(CGSizeMake(200, 28));
    }];
    titleLb.text = @"手机号码登录/注册";
    titleLb.textColor = [UIColor whiteColor];
    titleLb.font = [UIFont systemFontOfSize:20];
    
    //手机验证后可直接注册登录 5 13
    UILabel *detailLb = [[UILabel alloc] init];
    [self.view addSubview:detailLb];
    [detailLb mas_makeConstraints:^(MASConstraintMaker *make) {
        MY_STRONG;
        make.left.mas_equalTo(strongSelf.view.mas_left).offset(21);
        make.top.mas_equalTo(titleLb.mas_bottom).offset(5);
        make.size.mas_equalTo(CGSizeMake(200, 18));
    }];
    detailLb.text = @"手机验证后可直接注册登录";
    detailLb.textColor = [[UIColor whiteColor] colorWithAlphaComponent:0.69];
    detailLb.font = [UIFont systemFontOfSize:13];
    
    UIView *cellBgV = [[UIView alloc] init];
    [self.view addSubview:cellBgV];
    [cellBgV mas_makeConstraints:^(MASConstraintMaker *make) {
        MY_STRONG;
        make.top.mas_equalTo(detailLb.mas_bottom).offset(130-50);
        make.left.right.bottom.equalTo(strongSelf.view);
    }];
    cellBgV.backgroundColor = [UIColor clearColor];
    
    UIView *bgView = [[UIView alloc] init];
    [cellBgV addSubview:bgView];
    [bgView mas_makeConstraints:^(MASConstraintMaker *make) {
        MY_STRONG;
        make.top.mas_equalTo(cellBgV.mas_top).offset(50);
        make.left.right.bottom.equalTo(strongSelf.view);
    }];
    bgView.backgroundColor = kColorWithHex(0xF2F4FC);
    
    UIButton *bottomBtn = [[UIButton alloc] init];
    [bgView addSubview:bottomBtn];
    [bottomBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.mas_equalTo(bgView.mas_bottom).offset(-48);
        make.centerX.equalTo(bgView);
        make.size.mas_equalTo(CGSizeMake(300, 18));
    }];
    bottomBtn.backgroundColor = [UIColor clearColor];
    [bottomBtn setTitle:@"登录代表您同意《服务协议》和《隐私协议》" forState:UIControlStateNormal];
    bottomBtn.titleLabel.font = [UIFont systemFontOfSize:13];
    [bottomBtn setTitleColor:kColorWithHex(0x8B8B8B) forState:UIControlStateNormal];
    [bottomBtn addTapBlock:^(UIButton * _Nonnull btn) {
        // 跳转 网页
//        [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"https://www.baidu.com"] options:@{} completionHandler:^(BOOL success) {
//        }];
        // 跳转 html 网页
        NSString *str = @"https://www.baidu.com";
        MYSimpleWebVC *vc = [[MYSimpleWebVC alloc] initWithURLString:str];
        [self.navigationController pushViewController:vc animated:YES];
        
    }];
    [bgView layoutIfNeeded];
    [bgView round:20 RectCorners:UIRectCornerTopLeft|UIRectCornerTopRight];
    
    
    UIView *loginTopView = [[UIView alloc] init];
    [cellBgV addSubview:loginTopView];
    self.loginTopView = loginTopView;
    [loginTopView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(bgView.mas_top).offset(-50);
        make.left.mas_equalTo(bgView.mas_left).offset(10);
        make.right.mas_equalTo(bgView.mas_right).offset(-10);
//        make.height.mas_greaterThanOrEqualTo(@(300));
        make.height.mas_equalTo(50);
//        make.bottom.mas_equalTo(bgView.mas_bottom).offset()
        
    }];
    loginTopView.backgroundColor = [UIColor whiteColor];
    [loginTopView layoutIfNeeded];
    [loginTopView round:20 RectCorners:UIRectCornerTopLeft|UIRectCornerTopRight];
    
    UIView *loginTopLeftView = [[UIView alloc] init];
    [loginTopView addSubview:loginTopLeftView];
    [loginTopLeftView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.left.equalTo(loginTopView);
        make.height.mas_equalTo(50);
        make.width.mas_equalTo(loginTopView.width/2);
    }];
    loginTopLeftView.backgroundColor = kColorWithHex(0xE4E7FF);
    self.loginTopLeftView = loginTopLeftView;
    
    UIView *loginTopRightView = [[UIView alloc] init];
    [loginTopView addSubview:loginTopRightView];
    [loginTopRightView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.right.equalTo(loginTopView);
        make.height.mas_equalTo(50);
        make.width.mas_equalTo(loginTopView.width/2);
    }];
    loginTopRightView.backgroundColor = [UIColor whiteColor];//kColorWithHex(0xE4E7FF);
    self.loginTopRightView = loginTopRightView;
    
    UIButton *verificationTopLoginBtn  = [[UIButton alloc] init];
    [loginTopLeftView addSubview:verificationTopLoginBtn];
    [verificationTopLoginBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.top.right.bottom.mas_equalTo(loginTopLeftView);
    }];
    verificationTopLoginBtn.backgroundColor = [UIColor whiteColor];//kColorWithHex(0xE4E7FF);
    [verificationTopLoginBtn layoutIfNeeded];
    [verificationTopLoginBtn round:10 RectCorners:UIRectCornerTopRight];
    [verificationTopLoginBtn setTitleColor:kColorWithHex(0x010192) forState:UIControlStateSelected];
    [verificationTopLoginBtn setTitleColor:[kColorWithHex(0x010192) colorWithAlphaComponent:0.48] forState:UIControlStateNormal];
    verificationTopLoginBtn.selected = YES;
    [verificationTopLoginBtn setTitle:@"手机验证码登录" forState:UIControlStateNormal];
    verificationTopLoginBtn.titleLabel.font = [UIFont systemFontOfSize:14];
    self.verificationTopLoginBtn = verificationTopLoginBtn;
    [verificationTopLoginBtn addTapBlock:^(UIButton * _Nonnull btn) {
        MY_STRONG;
        if (btn.selected){
            return;
        }
        strongSelf.loginTopLeftView.backgroundColor = kColorWithHex(0xE4E7FF);
        strongSelf.loginTopRightView.backgroundColor = [UIColor whiteColor];
        strongSelf.pwdTopLoginBtn.backgroundColor = kColorWithHex(0xE4E7FF);
        strongSelf.verificationTopLoginBtn.backgroundColor = [UIColor whiteColor];
        strongSelf.verificationTopLoginBtn.selected = YES;
        strongSelf.pwdTopLoginBtn.selected = NO;
        [strongSelf.verificationTopLoginBtn round:10 RectCorners:UIRectCornerTopRight];
        [strongSelf.pwdTopLoginBtn round:10 RectCorners:UIRectCornerBottomLeft];
        
        strongSelf.verificationLoginView.hidden = NO;
        strongSelf.pwdLoginView.hidden = YES;
        
//        strongSelf.
//        strongSelf.loginTopView.height = 300;
//        [strongSelf.loginTopView layoutIfNeeded];
//        strongSelf.loginTopView.backgroundColor = [UIColor greenColor];
    }];
    
    UIButton *pwdTopLoginBtn = [[UIButton alloc] init];
    [loginTopRightView addSubview:pwdTopLoginBtn];
    [pwdTopLoginBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.top.right.bottom.mas_equalTo(loginTopRightView);
    }];
    pwdTopLoginBtn.backgroundColor = kColorWithHex(0xE4E7FF);
    
    [pwdTopLoginBtn layoutIfNeeded];
    [pwdTopLoginBtn round:10 RectCorners:UIRectCornerBottomLeft];
    [pwdTopLoginBtn setTitleColor:kColorWithHex(0x010192) forState:UIControlStateSelected];
    [pwdTopLoginBtn setTitleColor:[kColorWithHex(0x010192) colorWithAlphaComponent:0.48] forState:UIControlStateNormal];
    [pwdTopLoginBtn setTitle:@"账号密码登录" forState:UIControlStateNormal];
    pwdTopLoginBtn.titleLabel.font = [UIFont systemFontOfSize:14];
    self.pwdTopLoginBtn = pwdTopLoginBtn;
    [pwdTopLoginBtn addTapBlock:^(UIButton * _Nonnull btn) {
        MY_STRONG;
        if (btn.selected){
            return;
        }
        strongSelf.loginTopLeftView.backgroundColor = [UIColor whiteColor];
        strongSelf.loginTopRightView.backgroundColor = kColorWithHex(0xE4E7FF);
        strongSelf.verificationTopLoginBtn.backgroundColor = kColorWithHex(0xE4E7FF);
        strongSelf.pwdTopLoginBtn.backgroundColor = [UIColor whiteColor];
        strongSelf.verificationTopLoginBtn.selected = NO;
        strongSelf.pwdTopLoginBtn.selected = YES;
        [strongSelf.verificationTopLoginBtn round:10 RectCorners:UIRectCornerBottomRight];
        [strongSelf.pwdTopLoginBtn round:10 RectCorners:UIRectCornerTopLeft];
        
        strongSelf.verificationLoginView.hidden = YES;
        strongSelf.pwdLoginView.hidden = NO;
        
//        strongSelf.loginTopView.height = 340;
//        [strongSelf.loginTopView layoutIfNeeded];
//        strongSelf.loginTopView.backgroundColor = [UIColor redColor];
    }];
    
    // 手机验证登录
    UIView *verificationLoginView = [[UIView alloc] init];
    [cellBgV addSubview:verificationLoginView];
    [verificationLoginView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(loginTopView.mas_bottom).offset(-1);
        make.left.right.equalTo(loginTopView);
        make.height.mas_equalTo(250);
    }];
    verificationLoginView.backgroundColor = [UIColor whiteColor];
    [verificationLoginView layoutIfNeeded];
    [verificationLoginView round:20 RectCorners:UIRectCornerBottomLeft|UIRectCornerBottomRight];
    verificationLoginView.hidden = NO;
    self.verificationLoginView = verificationLoginView;
    
    [self setUIWithVerificationLoginView:verificationLoginView];


    // 账号密码登录
    UIView *pwdLoginView = [[UIView alloc] init];
    [cellBgV addSubview: pwdLoginView];
    [pwdLoginView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(loginTopView.mas_bottom).offset(-1);
        make.left.right.equalTo(loginTopView);
        make.height.mas_equalTo(290);
    }];
    pwdLoginView.backgroundColor = [UIColor whiteColor];
    [pwdLoginView layoutIfNeeded];
    [pwdLoginView round:20 RectCorners:UIRectCornerBottomLeft|UIRectCornerBottomRight];
    pwdLoginView.hidden = YES;
    self.pwdLoginView = pwdLoginView;
    [self setUIWithPwdLoginView:pwdLoginView];
    
    
}
- (void)setUIWithPwdLoginView:(UIView *)pwdLoginView{
//    MY_WEAK;
    UILabel *pwdAccountLb = [[UILabel alloc] init];
    [pwdLoginView addSubview:pwdAccountLb];
    [pwdAccountLb mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(pwdLoginView.mas_top).offset(20);
        make.left.mas_equalTo(pwdLoginView.mas_left).offset(28);
        make.height.mas_equalTo(@(17));
    }];
    pwdAccountLb.textColor = kColorWithHex(0x010192);
    pwdAccountLb.font = [UIFont systemFontOfSize:12];
    pwdAccountLb.text = @"账号/手机号";
    
    UITextField *pwdAccountTextField = [[UITextField alloc] init];
    [pwdLoginView addSubview:pwdAccountTextField];
    self.pwdAccountTextField = pwdAccountTextField;
    pwdAccountTextField.keyboardType = UIKeyboardTypeDefault;
    pwdAccountTextField.returnKeyType = UIReturnKeyNext;
    pwdAccountTextField.delegate = self;
    [pwdAccountTextField mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(pwdAccountLb.mas_bottom).offset(9);
        make.left.mas_equalTo(pwdLoginView.mas_left).offset(28);
        make.right.mas_equalTo(pwdLoginView.mas_right).offset(-28);
        make.height.mas_equalTo(@(40));
    }];
    [self setTextField:pwdAccountTextField placeholder:@"请输入登录账号/手机号"];
    
    UILabel *pwdPwdLb = [[UILabel alloc] init];
    [pwdLoginView addSubview:pwdPwdLb];
    [pwdPwdLb mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(pwdAccountTextField.mas_bottom).offset(10);
        make.left.mas_equalTo(pwdLoginView.mas_left).offset(28);
        make.height.mas_equalTo(@(17));
    }];
    pwdPwdLb.textColor = kColorWithHex(0x010192);
    pwdPwdLb.font = [UIFont systemFontOfSize:12];
    pwdPwdLb.text = @"密码";
    
    UITextField *pwdPwdTextField = [[UITextField alloc] init];
    [pwdLoginView addSubview:pwdPwdTextField];
    self.pwdPwdTextField = pwdPwdTextField;
    pwdPwdTextField.keyboardType = UIKeyboardTypeDefault;
    pwdPwdTextField.returnKeyType = UIReturnKeyDone;
    pwdPwdTextField.delegate = self;
    [pwdPwdTextField mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(pwdPwdLb.mas_bottom).offset(9);
        make.left.mas_equalTo(pwdLoginView.mas_left).offset(28);
        make.right.mas_equalTo(pwdLoginView.mas_right).offset(-28);
        make.height.mas_equalTo(@(40));
    }];
    [self setTextField:pwdPwdTextField placeholder:@"请输入短信验证码"];
    
    UIView *rightBackGroundView = [[UIView alloc] init];
    [pwdPwdTextField addSubview: rightBackGroundView];
    [rightBackGroundView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.top.bottom.mas_equalTo(pwdPwdTextField);
        make.width.mas_equalTo(@(44));
    }];
    
    
    UIButton *pwdIsSecretBtn = [[UIButton alloc] init];
    [pwdPwdTextField addSubview: pwdIsSecretBtn];
    self.pwdIsSecretBtn = pwdIsSecretBtn;
    [pwdIsSecretBtn mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.right.mas_equalTo(verificationVerfiTextField.mas_right).offset(-13);
        make.right.top.bottom.mas_equalTo(pwdPwdTextField);
        make.width.mas_equalTo(@(44));
    }];
    [pwdIsSecretBtn setImage:[UIImage svgImageNamed:@"pwd_close" size:CGSizeMake(14, 12)] forState:UIControlStateNormal];
    [pwdIsSecretBtn setImage:[UIImage svgImageNamed:@"pwd_open" size:CGSizeMake(14, 10)] forState:UIControlStateSelected];
    [pwdIsSecretBtn addTapBlock:^(UIButton * _Nonnull btn) {
        btn.selected = !btn.selected;
        pwdPwdTextField.secureTextEntry = !btn.selected;
    }];
    
    UIButton *pwdBottomLoginBtn = [[UIButton alloc] init];
    [pwdLoginView addSubview:pwdBottomLoginBtn];
    self.pwdBottomLoginBtn = pwdBottomLoginBtn;
    [pwdBottomLoginBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(pwdPwdTextField.mas_bottom).offset(30);
        make.left.right.equalTo(pwdPwdTextField);
        make.height.mas_equalTo(@(40));
    }];
    [pwdBottomLoginBtn setTitle:@"登录" forState:UIControlStateNormal];
    [pwdBottomLoginBtn setTitleColor:[UIColor whiteColor]  forState:UIControlStateNormal];
    pwdBottomLoginBtn.titleLabel.font = [UIFont systemFontOfSize:15];

    [pwdBottomLoginBtn layoutIfNeeded];
    [pwdBottomLoginBtn round:20 RectCorners:UIRectCornerTopLeft|UIRectCornerTopRight|UIRectCornerBottomLeft|UIRectCornerBottomRight];
    [pwdBottomLoginBtn setBackgroundColor:kColorWithHex(0xC8CCE1)];
    [pwdBottomLoginBtn addTapBlock:^(UIButton * _Nonnull btn) {
        // 跳转
        
    }];
    
    UIButton *pwdForgetBtn = [[UIButton alloc] init];
    [pwdLoginView addSubview:pwdForgetBtn];
    self.pwdForgetBtn = pwdForgetBtn;
    [pwdForgetBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(pwdBottomLoginBtn.mas_bottom).offset(20);
        make.left.right.equalTo(pwdBottomLoginBtn);
        make.height.mas_equalTo(@(17));
    }];
    [pwdForgetBtn setTitleColor:[kColorWithHex(0x010192) colorWithAlphaComponent:0.64] forState:UIControlStateNormal];
    [pwdForgetBtn setTitle:@"忘记密码" forState:UIControlStateNormal];
    pwdForgetBtn.titleLabel.font = [UIFont systemFontOfSize:12];
    [pwdForgetBtn addTapBlock:^(UIButton * _Nonnull btn) {
        [self.navigationController pushViewController:[UIViewController new] animated:YES];
    }];
    
}
- (void)setUIWithVerificationLoginView:(UIView *)verificationLoginView{
    MY_WEAK;
    UILabel *verificationPhoneLb = [[UILabel alloc] init];
    [verificationLoginView addSubview:verificationPhoneLb];
    [verificationPhoneLb mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(verificationLoginView.mas_top).offset(20);
        make.left.mas_equalTo(verificationLoginView.mas_left).offset(28);
        make.height.mas_equalTo(@(17));
    }];
    verificationPhoneLb.textColor = kColorWithHex(0x010192);
    verificationPhoneLb.font = [UIFont systemFontOfSize:12 weight:UIFontWeightMedium];
    verificationPhoneLb.text = @"手机号码";
    
    UITextField *verificationPhoneTextField = [[UITextField alloc] init];
    [verificationLoginView addSubview:verificationPhoneTextField];
    self.verificationPhoneTextField = verificationPhoneTextField;
    verificationPhoneTextField.keyboardType = UIKeyboardTypeNumberPad;
    verificationPhoneTextField.returnKeyType = UIReturnKeyNext;
    verificationPhoneTextField.delegate = self;
    [verificationPhoneTextField mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(verificationPhoneLb.mas_bottom).offset(9);
        make.left.mas_equalTo(verificationLoginView.mas_left).offset(28);
        make.right.mas_equalTo(verificationLoginView.mas_right).offset(-28);
        make.height.mas_equalTo(@(40));
    }];
    [self setTextField:verificationPhoneTextField placeholder:@"请输入正确的手机号码"];
    
    UILabel *verificationVerfiLb = [[UILabel alloc] init];
    [verificationLoginView addSubview:verificationVerfiLb];
    [verificationVerfiLb mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(verificationPhoneTextField.mas_bottom).offset(10);
        make.left.mas_equalTo(verificationLoginView.mas_left).offset(28);
        make.height.mas_equalTo(@(17));
    }];
    verificationVerfiLb.textColor = kColorWithHex(0x010192);
    verificationVerfiLb.font = [UIFont systemFontOfSize:12 weight:UIFontWeightMedium];
    verificationVerfiLb.text = @"验证码";
    
    UITextField *verificationVerfiTextField = [[UITextField alloc] init];
    [verificationLoginView addSubview:verificationVerfiTextField];
    self.verificationVerfiTextField = verificationVerfiTextField;
    verificationVerfiTextField.keyboardType = UIKeyboardTypeNumberPad;
    verificationVerfiTextField.returnKeyType = UIReturnKeyDone;
    verificationVerfiTextField.delegate = self;
    [verificationVerfiTextField mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(verificationVerfiLb.mas_bottom).offset(9);
        make.left.mas_equalTo(verificationLoginView.mas_left).offset(28);
        make.right.mas_equalTo(verificationLoginView.mas_right).offset(-28);
        make.height.mas_equalTo(@(40));
    }];
    [self setTextField:verificationVerfiTextField placeholder:@"请输入短信验证码"];
    [self addVerificationTextField:verificationVerfiTextField];// 加入验证码
    
    
    UIButton *verificationBottomLoginBtn = [[UIButton alloc] init];
    [verificationLoginView addSubview:verificationBottomLoginBtn];
    self.verificationBottomLoginBtn = verificationBottomLoginBtn;
    [verificationBottomLoginBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(verificationVerfiTextField.mas_bottom).offset(30);
        make.left.right.equalTo(verificationVerfiTextField);
        make.height.mas_equalTo(@(40));
    }];
    [verificationBottomLoginBtn setTitle:@"注册/登录" forState:UIControlStateNormal];
    [verificationBottomLoginBtn setTitleColor:[UIColor whiteColor]  forState:UIControlStateNormal];
    verificationBottomLoginBtn.titleLabel.font = [UIFont systemFontOfSize:15];

    [verificationBottomLoginBtn layoutIfNeeded];
    [verificationBottomLoginBtn round:20 RectCorners:UIRectCornerTopLeft|UIRectCornerTopRight|UIRectCornerBottomLeft|UIRectCornerBottomRight];
    [verificationBottomLoginBtn setBackgroundColor:kColorWithHex(0xC8CCE1)];
    [verificationBottomLoginBtn addTapBlock:^(UIButton * _Nonnull btn) {
        [self.navigationController pushViewController:[[JQUserSetPwdVC alloc] init] animated:YES];
    }];
}
- (void)addVerificationTextField:(UITextField *)verificationVerfiTextField{
    MY_WEAK;
    UIView *rightBackGroundView = [[UIView alloc] init];
    [verificationVerfiTextField addSubview: rightBackGroundView];
    [rightBackGroundView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.top.bottom.mas_equalTo(verificationVerfiTextField);
        make.width.mas_equalTo(@(90));
    }];
    
    // 获取 验证码 重发  倒计时 xxs重发
//    #DDE3FB
    UIView *verticalLineV = [[UIView alloc] init];
    [verificationVerfiTextField addSubview:verticalLineV];
    [verticalLineV mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(verificationVerfiTextField.mas_top).offset(6);
        make.bottom.mas_equalTo(verificationVerfiTextField.mas_bottom).offset(-6);
        make.width.mas_equalTo(@(1));
        make.right.mas_equalTo(verificationVerfiTextField.mas_right).offset(-90);
    }];
    verticalLineV.backgroundColor = kColorWithHex(0xDDE3FB);
    
    UIButton *verificationBtn = [[UIButton alloc] init];
    [verificationVerfiTextField addSubview: verificationBtn];
    self.verificationBtn = verificationBtn;
    [verificationBtn mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.right.mas_equalTo(verificationVerfiTextField.mas_right).offset(-13);
        make.right.top.bottom.mas_equalTo(verificationVerfiTextField);
        make.left.mas_equalTo(verticalLineV.mas_right).offset(0);
        
    }];
    [verificationBtn setTitle:@"获取验证码" forState:UIControlStateNormal];
//    [verificationBtn setTitleColor:kColorWithHex(0x010192) forState:UIControlStateNormal];
    [verificationBtn setTitleColor:[kColorWithHex(0x010192) colorWithAlphaComponent:0.3] forState:UIControlStateDisabled];
    [verificationBtn setTitleColor:kColorWithHex(0x010192) forState:UIControlStateNormal];
    verificationBtn.enabled = NO;
    
    verificationBtn.titleLabel.font = [UIFont systemFontOfSize:13];
    
    // 倒计时 效果
    [verificationBtn addTapBlock:^(UIButton * _Nonnull btn) {
        MY_STRONG;
        [strongSelf receiveCheckNumButton];
    }];
}
//获取验证码倒计时
- (void)receiveCheckNumButton{
    __block int timeout= 60; //倒计时时间
    dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
    dispatch_source_t _timer = dispatch_source_create(DISPATCH_SOURCE_TYPE_TIMER, 0, 0,queue);
    dispatch_source_set_timer(_timer,dispatch_walltime(NULL, 0),1.0*NSEC_PER_SEC, 0); //每秒执行
    dispatch_source_set_event_handler(_timer, ^{
        if(timeout<=0){ //倒计时结束，关闭
            dispatch_source_cancel(_timer);
            dispatch_async(dispatch_get_main_queue(), ^{
                //设置界面的按钮显示 根据自己需求设置
                [self.verificationBtn setTitle:@"获取验证码" forState:UIControlStateNormal];
                self.verificationBtn.enabled = YES;
            });
        }else{
            int seconds = timeout;
            NSString *strTime = [NSString stringWithFormat:@"%.ds", seconds];
            dispatch_async(dispatch_get_main_queue(), ^{
                //设置界面的按钮显示 根据自己需求设置
                [UIView beginAnimations:nil context:nil];
                [UIView setAnimationDuration:1];
                [self.verificationBtn setTitle:[NSString stringWithFormat:@"%@重发",strTime] forState:UIControlStateNormal];
                [UIView commitAnimations];
                self.verificationBtn.enabled = NO;
            });
            timeout--;
        }
    });
    dispatch_resume(_timer);
}
// 底部登录按钮的 渐变效果
- (void)setGradientLayerWithView:(UIView *)view{
    // gradient
    if (self.verificationGl) {
        [self.verificationGl removeFromSuperlayer];
        self.verificationGl = nil;
    }
    
    CAGradientLayer *gl = [CAGradientLayer layer];
    self.verificationGl = gl;
    gl.frame = view.bounds;//CGRectMake(38,476,299,40);
    gl.startPoint = CGPointMake(1, 0.5);
    gl.endPoint = CGPointMake(0, 0.5);
    gl.colors = @[(__bridge id)[UIColor colorWithRed:49/255.0 green:0/255.0 blue:186/255.0 alpha:1.0].CGColor, (__bridge id)[UIColor colorWithRed:0/255.0 green:0/255.0 blue:229/255.0 alpha:1.0].CGColor];
    gl.locations = @[@(0), @(1.0f)];
    
    [view.layer addSublayer:gl];
    [view.layer insertSublayer:gl atIndex:0];
    
//    [gl removeFromSuperlayer]
}
// 底部登录按钮的 渐变效果
- (void)setGradientLayerWithPwdView:(UIView *)view{
    // gradient
    if (self.pwdGl) {
        [self.pwdGl removeFromSuperlayer];
        self.pwdGl = nil;
    }
    
    CAGradientLayer *gl = [CAGradientLayer layer];
    self.pwdGl = gl;
    gl.frame = view.bounds;//CGRectMake(38,476,299,40);
    gl.startPoint = CGPointMake(1, 0.5);
    gl.endPoint = CGPointMake(0, 0.5);
    gl.colors = @[(__bridge id)[UIColor colorWithRed:49/255.0 green:0/255.0 blue:186/255.0 alpha:1.0].CGColor, (__bridge id)[UIColor colorWithRed:0/255.0 green:0/255.0 blue:229/255.0 alpha:1.0].CGColor];
    gl.locations = @[@(0), @(1.0f)];
    
    [view.layer addSublayer:gl];
    [view.layer insertSublayer:gl atIndex:0];
    
//    [gl removeFromSuperlayer]
}
// textfield 自定义UI
- (void)setTextField:(UITextField *)textField placeholder:(NSString *)placeholder {
    textField.placeholder = [NSString
                             stringWithFormat:@"   %@", placeholder];
    textField.backgroundColor = kColorWithHex(0xF2F4FC);
    [textField layoutIfNeeded];
    [textField round:5 RectCorners:UIRectCornerTopLeft|UIRectCornerTopRight|UIRectCornerBottomLeft|UIRectCornerBottomRight];
    
    [textField setValue:[NSNumber numberWithInt:10] forKey:@"paddingLeft"];
//    verificationTextField.tintColor = kColorWithHex(0x010192);
    textField.textColor = kColorWithHex(0x010192);
    textField.font = [UIFont systemFontOfSize:14];
    if (@available(iOS 13.0, *)){
        textField.attributedPlaceholder = [[NSAttributedString alloc]initWithString:textField.placeholder attributes:@{NSForegroundColorAttributeName:[kColorWithHex(0x010192) colorWithAlphaComponent:0.3], NSFontAttributeName:[UIFont systemFontOfSize:13]}];
    }else{
        [textField setValue:[kColorWithHex(0x010192) colorWithAlphaComponent:0.3] forKeyPath:@"_placeholderLabel.textColor"];
        [textField setValue:[UIFont boldSystemFontOfSize:13] forKeyPath:@"_placeholderLabel.font"];
    }
}
- (void)addTopView{
//    login_background  375  372
    
    UIImageView *topImageV = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 372*SCREEN_WIDTH/375)];
    [self.view addSubview:topImageV];
    topImageV.image = [UIImage imageNamed:@"login_background"];

}
- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    self.navigationController.navigationBar.hidden = YES;
}
- (void)viewWillDisappear:(BOOL)animated{
    [super viewWillDisappear:animated];
    self.navigationController.navigationBar.hidden = NO;
}


#pragma mark - UITextDeleagte
- (void)textFieldDidEndEditing:(UITextField *)textField{
    [self textFieldDidChangeSelectionComond:textField];
}
// iOS13 系统才走的方法
- (void)textFieldDidChangeSelection:(UITextField *)textField{
    [self textFieldDidChangeSelectionComond:textField];
}
// 代理来监听textField输入字符变化
- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string{
    if (@available(iOS 13.0, *)) {
        
    }else{
        [self textFieldDidChangeSelectionComond:textField];
    }
    return YES;
}
// 监听textField 公用方法
- (void)textFieldDidChangeSelectionComond:(UITextField *)textField{
    if ((textField == self.verificationPhoneTextField) && (textField.text.length == 11)) {
        self.verificationBtn.enabled = YES;
    }else{
        self.verificationBtn.enabled = NO;
    }
    if (textField == self.verificationPhoneTextField){
        if (textField.text.length && ![[textField.text substringToIndex:1] isEqualToString:@"1"]){
            [MYTipUtils showAlertString:@"手机号码必须1开头的号码"];
            [textField endEditing:YES];
            return;
        }
        if (textField.text.length > 11) {
            textField.text = [textField.text substringToIndex:11];
        }
    }
    if (textField == self.verificationVerfiTextField){
        if (textField.text.length > 6) {
            textField.text = [textField.text substringToIndex:6];
        }
    }
    if (self.verificationPhoneTextField.text.length == 11 && self.verificationVerfiTextField.text.length == 6) {
        [self setGradientLayerWithView:self.verificationBottomLoginBtn];
        self.verificationBottomLoginBtn.enabled = YES;
    }else{
        [self.verificationBottomLoginBtn setBackgroundColor:kColorWithHex(0xC8CCE1)];
        if (self.verificationGl) {
            [self.verificationGl removeFromSuperlayer];
            self.verificationGl = nil;
        }
        self.verificationBottomLoginBtn.enabled = NO;
    }
    
    if (self.pwdAccountTextField.text.length && (self.pwdPwdTextField.text.length > 6)) {
        [self setGradientLayerWithPwdView:self.pwdBottomLoginBtn];
        self.pwdBottomLoginBtn.enabled = YES;
    }else{
        [self.pwdBottomLoginBtn setBackgroundColor:kColorWithHex(0xC8CCE1)];
        if (self.pwdGl) {
            [self.pwdGl removeFromSuperlayer];
            self.pwdGl = nil;
        }
        self.pwdBottomLoginBtn.enabled = NO;
    }
}

@end
